package com.AAL.DAO;

import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IDeliveryMethodDAO;
import com.AAL.Model.DeliveryMethod;
import com.AAL.Utils.HibernateUtil;

public class DeliveryMethodDAO implements IDeliveryMethodDAO {

	@Override
	public DeliveryMethod saveAndUpdateDeliveryMethod(
			DeliveryMethod deliveryMethod) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(deliveryMethod);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return deliveryMethod;
	}

	@Override
	public DeliveryMethod deleteDeliveryMethod(int deliveryMethodID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			DeliveryMethod deliveryMethod = (DeliveryMethod) session.load(
					DeliveryMethod.class, deliveryMethodID);
			if (null != deliveryMethod) {
				session.delete(deliveryMethod);
			}
			session.getTransaction().commit();
			return deliveryMethod;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public DeliveryMethod getDeliveryMethod(int deliveryMethodID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		DeliveryMethod deliveryMethod = (DeliveryMethod) session.load(
				DeliveryMethod.class, deliveryMethodID);
		return deliveryMethod;
	}

	@Override
	public List<DeliveryMethod> getAllLstDeliveryMethod() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<DeliveryMethod> getLstDeliveryMethodByPurchaseContract(
			String PurchaseContractID) {
		// TODO Auto-generated method stub
		return null;
	}

}
